package com.cjkj.system.controller;

import com.cjkj.common.core.utils.DateUtils;
import com.cjkj.common.core.web.domain.AjaxResult;
import com.cjkj.system.domain.dto.TJ01ReportsDataReq;
import com.cjkj.system.service.ReportTJ01Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * 睡眠监测垫 报告控制器
 */
@RestController
@RequestMapping("reports/tj01")
@Validated
public class ReportTJ01Controller {

    @Resource
    private ReportTJ01Service reportTJ01Service;

    /**
     * 体测报告-睡眠
     * @return
     */
    @GetMapping("/sleep")
    public AjaxResult sleep(@NotNull(message = "就诊号不能为空！") Long visitNo,
                            @NotBlank(message = "查询日期不能为空！") String startTime) {
        Date date = DateUtils.parseDate(startTime);
        return AjaxResult.success(reportTJ01Service.sleep(visitNo, date));
    }

    /**
     * 体测报告-血氧
     * @return
     */
    @GetMapping("/spO2")
    public AjaxResult spo2(@NotNull(message = "就诊号不能为空！") Long visitNo,
                           @NotBlank(message = "查询日期不能为空！") String startTime){
        Date date = DateUtils.parseDate(startTime);
        return AjaxResult.success(reportTJ01Service.getSpO2Reports(visitNo, date));
    }

    /**
     * 体测报告-心率
     * @return
     */
    @GetMapping("/heartRate")
    public AjaxResult heartRate(@NotNull(message = "就诊号不能为空！") Long visitNo,
                                @NotBlank(message = "查询日期不能为空！") String startTime){
        Date date = DateUtils.parseDate(startTime);
        return AjaxResult.success(reportTJ01Service.getHeartRateReports(visitNo, date));
    }

    /**
     * 体测报告-呼吸
     * @return
     */
    @GetMapping("/breathRate")
    public AjaxResult breathRate(@NotNull(message = "就诊号不能为空！") Long visitNo,
                                 @NotBlank(message = "查询日期不能为空！") String startTime){
        Date date = DateUtils.parseDate(startTime);
        return AjaxResult.success(reportTJ01Service.getBreathRateReports(visitNo, date));
    }

    /**
     * 获取患者睡眠监测报告
     * @return
     */
    @GetMapping("getSleepReportData")
    public AjaxResult getSleepReportData(@Valid TJ01ReportsDataReq req) {
        return AjaxResult.success(reportTJ01Service.getSleepReportData(req));
    }
}
